<link	href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<script type="text/javascript" src="js/jquery-ui.js"></script>
<link rel="stylesheet"
	type="text/css" href="admin/css/jsDatePick_ltr.min.css" />

<script
	type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>

<script type="text/javascript">
$(document).ready(function(){
	$(".hang").mouseover(function(){	
		$(this).addClass("nenhang");	
	});
	
	$(".hang").mouseout(function(){	
		$(this).removeClass("nenhang");	
	});
});
window.onload = function(){

new JsDatePick({

useMode:2,

target:"txttime1",
dateFormat:"%Y-%m-%d"

});

};

function deleteclick(vitri){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("showlist").innerHTML=xmlhttp.responseText;
										  }
									  }
	xmlhttp.open("GET","content_salary/ajax_delete_checktime.php?vitri="+vitri,true);
	xmlhttp.send();
}
</script>
<?php 
$gttime=date("Y-m-d");
$mkq_check=array($l_can_import,$l_can_not_import);
$show_hd=1;
?>
<div id="contains" style="height:100%;">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant;?> &rarr; <?php echo $l_ml_tinh_luong;?> &rarr; <?php echo $l_search_salary;?> </div>
	<div class="content_code" style="height:100%;">
		<div class="approval-right" style="padding-right:10px; height:100%;">

			<div  style="width:100%;border: 1px solid silver; padding: 10px 0; ">
				<form action="salary.php?content=import_checktime" method="post"
					name="formexcel" enctype="multipart/form-data">
						<table style="width:100%; padding-left:10px;">
							<tr>
								<td  class="tdfirst"><?php echo $l_time;?></td>
								<td><input type="text" id="txttime" name="txttime" value="<?=$gttime?>" class="in_testfield" style="width:185px;float:left;height:24px;" readonly="readonly"/></td>
							</tr>
							<tr>
								<td  class="tdfirst"><?=$l_importexcel?></td>
								<td><input name="fileexcel" type="file" value="ad" onchange="document.formexcel.submit()" style="width:200px;float:left;height:24px;" /></td>
							</tr>
						</table>
					
				</form>
			</div>
			<div style="width:100%" id="showlist">
			<?php
			if (isset($_FILES["fileexcel"])) {
				$show_hd=0;
				$mcheck=array();
				include '../operations/connection.php';
				$sql="SELECT sa_employee_salary_log.idlog 
				from sa_employee_salary_log 
				where sa_employee_salary_log.is_saved=1";
				$mkq=mysql_query($sql);
				if(mysql_num_rows($mkq)>0){
					while($rcheck=mysql_fetch_array($mkq)){
						$mcheck[]=$rcheck[idlog];
					}
				}
				
				$soluong=count($mcheck);
				$_SESSION['rs_mysheets']=array();
				unset($_SESSION['mysheets']);
				include 'CheckTime.php';
				include 'Classes/simplexlsx.class.php';
				date_default_timezone_set('Europe/London');

				$inputFileName = $_FILES['fileexcel']['tmp_name'];
				//$inputFileName = 'C://AppServ/www/ERP/ERP-PC/mau_saved.xlsx';
				//$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);//content_salary/CheckTimeSave.php
				echo '<div style="width:100%;text-align:left;padding-left:3px;padding-top:10px;padding-bottom:10px;" ><font color="red"><b>(*)</b></font> <font color="green"><b>'.$l_tb_import_sa.' ( <img src="images/check_sa.png" style="width:20px;height:20px" title="'.$mkq_check[0].'"/> )</b></font><br></div>';
				echo '<table style="width:100%;text-align:center;" class="rf-dt"><tr>';
				echo '<td class="rf-dt-shdr-c" width="20px"></td>';
				echo '<td class="rf-dt-shdr-c" width="20%">'.$l_employee_name.'</td>';
				echo '<td class="rf-dt-shdr-c" width="10%">'.$l_code.'</td>';
				echo '<td class="rf-dt-shdr-c" width="10%">'.$l_date.'</td>';
				echo '<td class="rf-dt-shdr-c" width="8%">'.$l_timecheckin.'</td>';
				echo '<td class="rf-dt-shdr-c" width="8%">'.$l_timecheckout.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_late.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_comebackearly.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_half_dayoff.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_all_dayoff.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_overtime.'</td>';
				echo '<td class="rf-dt-shdr-c" >'.$l_note.'</td>';
				echo '<td class="rf-dt-shdr-c" width="20px">'.$l_result_checkdata.'</td></tr>';

				$xlsx = new SimpleXLSX($inputFileName);
				// sheets numeration: 1,2,3....
				$myData = array();
				$xmlWorkBook =  $xlsx->getXMLWorkBook();
				$vitri=0;
				foreach ($xlsx->sheets() as $keysheet => $ws){
					$loadedSheetName = ''.$xlsx->getWorksheetName($xmlWorkBook, $keysheet-1);
					$sheetdate = '';
					$curR = 0;
					echo '<tr class="hang"><td colspan="13" class="rf-dt-c" style="text-align:left;"><b>',$loadedSheetName,'</b>';
					echo $sheetdate;
					echo '</td></tr>';
					$mySheets = array();
					foreach ($ws->sheetData->row as $row) {

						$curC = 0;
						$vcheck=0;
						foreach ($row->c as $keyc => $c) {
							//echo $c['r'];
							if($curR>=1){
								if ($curC==0) {
									$col_id = $xlsx->value($c);
								}
								elseif ($curC==1) {
									$col_name = $xlsx->value($c);
								}elseif ($curC==2){
									$col_date = date('Y-m-d', mktime(0,0,0,1,$xlsx->value($c)-1,1900));
									if($soluong>0){
										$ktdate=getdate(strtotime($col_date));
										$namthang=$ktdate[year]."-".$ktdate[mon];
										$gt=in_array($namthang,$mcheck);
										if($gt==true){
											$vcheck=1;
										}
									}
								}
								elseif ($curC==3){
									$col_in = $xlsx->value($c);
									if ($xlsx->value($c)!="") {
										$col_in = date('H:i', round($xlsx->value($c)*86400)-3600);
									}
								}
								elseif ($curC==4){
									$col_out = $xlsx->value($c);
									if ($xlsx->value($c)!="") {
										$col_out = date('H:i', round($xlsx->value($c)*86400)-3600);
									}
									$object = new CheckTime();
									$col_sheet = $col_date;
									$object->setDate($col_sheet,$col_date);
									$object->setCheckvalue($vcheck);
									$object->setVitri($vitri);
									$object->employeeID = $col_id;
									$object->employeeName = $col_name;
									$object->inTime($col_in);
									$object->outTime($col_out);
									$object->off($col_in, $col_out,$l_confirm_excel);
									
									if($object->checkvalue==0){
										$_SESSION['rs_mysheets'][$vitri]=$object;
									}
									
									//array_push($mySheets, $object);	
									$mySheets[$vitri]=$object;
									echo '<tr  class="hang">';
									
									echo '<td class="rf-dt-c">';
									echo '<img onclick="deleteclick('.$object->vitri.')" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="'.$l_delete.'" />';
									echo '</td>';
									
									echo '<td class="rf-dt-c" style="text-align:left;">';
									echo $object->employeeName;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									echo $object->employeeID;
									echo '</td>';

									echo '<td class="rf-dt-c">';

									echo $object->date;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->inTime != '0') echo $object->inTime;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->outTime != '0') echo $object->outTime;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->late != '0') echo $object->late;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->early != '0') echo $object->early;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->halfDayOff != '0') echo $object->halfDayOff;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->aDayOff != '0') echo $object->aDayOff;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									if ($object->overtime != '0') echo $object->overtime;
									echo '</td>';

									echo '<td class="rf-dt-c">';
									echo $object->note;
									echo '</td>';
									
									echo '<td class="rf-dt-c">';
									if($object->checkvalue==1){
										echo '<img src="images/Restricted Icon.jpg" style="width:20px;height:20px" title="'.$mkq_check[$object->checkvalue].'" />';
									}else{
										echo '<img src="images/check_sa.png" style="width:20px;height:20px" title="'.$mkq_check[$object->checkvalue].'"/>';
									}
									echo '</td>';
									
									echo '</tr>';
									break;
								}
							}
							$curC++;
						}
						
						$curR++;
						$vitri++;
					}
					//array_push($myData , $mySheets);
					$myData[$loadedSheetName] = $mySheets;
				}
				//var_dump($myData);
				$_SESSION['mysheets'] = $myData;
				echo '</table>';
				if(count($_SESSION['rs_mysheets'])>0){
					echo '<div style="width:100%;text-align:center;padding:20px;" > <a href="content_salary/CheckTimeSave.php"><input type="button" value="'.$l_save.'" class="btnupbg btnupload"/></a></div>';
				}else{
					echo '<div style="width:100%;text-align:center;padding:20px;font-weight:bold;color:red;">'.$l_salary_exit_not_input_spread_again.'</div>';
				}
				mysql_close($connection);
				
			}elseif (isset($_SESSION['mysheets']) && is_array($_SESSION['mysheets'])){
				$show_hd=0;
				include 'CheckTime.php';
				include '../operations/connection.php';
				$tempsql = "";
				echo '<div style="width:100%;text-align:left;padding-left:3px;padding-top:10px;padding-bottom:10px;" ><font color="red"><b>(*)</b></font> <font color="green"><b>'.$l_tb_import_sa.' ( <img src="images/check_sa.png" style="width:20px;height:20px" title="'.$mkq_check[0].'"/> )</b></font><br></div>';
				echo '<table style="width:100%;text-align:center;" class="rf-dt"><tr>';
				//echo '<td class="rf-dt-shdr-c" width="20px"></td>';
				echo '<td class="rf-dt-shdr-c" width="20%">'.$l_employee_name.'</td>';
				echo '<td class="rf-dt-shdr-c" width="10%">'.$l_code.'</td>';
				echo '<td class="rf-dt-shdr-c" width="10%">'.$l_date.'</td>';
				echo '<td class="rf-dt-shdr-c" width="8%">'.$l_timecheckin.'</td>';
				echo '<td class="rf-dt-shdr-c" width="8%">'.$l_timecheckout.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_late.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_comebackearly.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_half_dayoff.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_all_dayoff.'</td>';
				echo '<td class="rf-dt-shdr-c" width="5%">'.$l_overtime.'</td>';
				echo '<td class="rf-dt-shdr-c" >'.$l_note.'</td>';
				echo '<td class="rf-dt-shdr-c" width="20px">'.$l_result_checkdata.'</td></tr>';
				if(count($_SESSION['mysheets'])>0){
					foreach ($_SESSION['mysheets'] as $sheetkey =>  $sheetobject){
						echo '<tr  class="hang"><td colspan="13" class="rf-dt-c" style="text-align:left;"><b>',$sheetkey,'</b></tr>';
						foreach ($sheetobject as $key =>  $object){
							$CT = unserialize (serialize ($object));
							echo '<tr  class="hang">';
							
							//echo '<td class="rf-dt-c">';
							//echo '<img onclick="deleteclick('.$object->vitri.')" src="images/del.png" style="width:20px;height:20px;cursor:pointer;" title="'.$l_delete.'" />';
							//echo '</td>';
							
							echo '<td class="rf-dt-c" style="text-align:left;">';
							echo $CT->employeeName;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							echo $CT->employeeID;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
	
							echo $CT->date;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->inTime != '0') echo $CT->inTime;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->outTime != '0') echo $CT->outTime;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->late != '0') echo $CT->late;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->early != '0') echo $CT->early;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->halfDayOff != '0') echo $CT->halfDayOff;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->aDayOff != '0') echo $CT->aDayOff;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							if ($CT->overtime != '0') echo $CT->overtime;
							echo '</td>';
	
							echo '<td class="rf-dt-c">';
							echo $CT->note;
							echo '</td>';
							
							echo '<td class="rf-dt-c">';
							if($object->checkvalue==1){
								echo '<img src="images/Restricted Icon.jpg" style="width:20px;height:20px" title="'.$mkq_check[$object->checkvalue].'" />';
							}else{
								echo '<img src="images/check_sa.png" style="width:20px;height:20px" title="'.$mkq_check[$object->checkvalue].'"/>';
							}
							echo '</td>';
							
							echo '</tr>';
						}
					}
				}else{
					echo '<tr  class="hang"><td colspan="13" class="rf-dt-c" style="text-align:left;">'.$l_list_emplty.'</tr>';
				}
				
				echo '</table>';
				if(isset($_SESSION['rs_mysheets']) && count($_SESSION['rs_mysheets'])>0){
					echo '<div style="width:100%;text-align:center;padding:20px;" > <a href="content_salary/CheckTimeSave.php"><input type="button" value="'.$l_save.'" class="btnupbg btnupload"/></a></div>';
				}else{
					echo '<div style="width:100%;text-align:center;padding:20px;font-weight:bold;color:red;">'.$l_salary_exit_not_input_spread_again.'</div>';
				}
				mysql_close($connection);
			}else{
				$show_hd=1;
			}
			
			if($show_hd==1){
			?>
			</div>
			<br><br>
			<div  style="width:100%;border: 1px solid silver; padding: 10px 0; margin-bottom: 30px;">
				<table width="100%">
					<tr>
						<td>
							<table width="100%" style="padding:5px;">
								<tr><td colspan="2" style="color:red;"><b>(*)<?php echo $l_please_prepare_standard_file_format;?></b></td></tr>
								<tr><td width="30px"><img src="images/icon_note_blu.gif" /></td><td><span style="color:green;" ><b><?php echo $l_input_format_excel;?></b></span></td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;border-color: green;border: 1;border-width: 2px;" ><b><font color="red" >1</font></b></span></td><td><?php echo $l_put_an_empty_line_above;?></td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;" ><b><font color="red" >2</font></b></span></td><td><?php echo $l_please_delete_the_extra_data_lines_below;?></td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;" ><b><font color="red" >3</font></b></span></td><td><?php echo $l_input_data_format;?></td></tr>
								<tr><td></td><td><?php echo $l_the_data_follow_the_order_required;?>:</td></tr>
								<tr><td></td><td style="padding-left:5px;">+ <?php echo $l_employeecode;?></td></tr>
								<tr><td></td><td style="padding-left:5px;">+ <?php echo $l_employee_name;?></td></tr>
								<tr><td></td><td style="padding-left:5px;">+ <?php echo $l_date;?></td></tr>
								<tr><td></td><td style="padding-left:5px;">+ <?php echo $l_timecheckin;?></td></tr>
								<tr><td></td><td style="padding-left:5px;">+ <?php echo $l_timecheckout;?></td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;" ><b><font color="red" >4</font></b></span></td><td><?php echo $l_employeecode;?> (<b>EmployeeCode</b>)</td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;" ><b><font color="red" >5</font></b></span></td><td><?php echo $l_date_format;?></td></tr>
								<tr><td align="right" style="padding:5px;"><span style="background-color: #d6fbf4;" ><b><font color="red" >6</font></b></span></td><td><?php echo $l_time_format;?></td></tr>
							</table>
						</td>
					</tr>
					<tr>
						<td><img src="images/import_excel_help.jpg" width="100%" /></td>
					</tr>
				</table>
			</div>
			<?php }?>

		</div>
	</div>
</div>
